<?php
namespace Merchant\Controller;
use Think\Controller;
class ApiController extends CommController
{
    //前台轮播图接口
    public function index()
    {
        $id = $_REQUEST['id'];
        $where = [
            'bid' => $id,
            'del'=>1,
            'state'=>1
        ];
        $data = M('Lb')->where($where)->select();
        foreach ($data as $key => $val) {
            $time = time();;
            //有效时间  当前时间 减去 结束时间
            $map[$key]['lbtime'] = $time - $val['stop'];
            foreach($map as $k => $v){
                if($v['lbtime']> 0){
                    $lb[$key]['img'] = $val['img'];
                }
            }
        }
        echo $this->e_json($lb);
    }
    //商品的接口
    public function goods(){
        $where = [
            'g.del'=>1,
            'g.state'=>1
        ];
        $define = ['g.*','t.name tname','p.img','count(p.id) num','b.name bname'];
        $list = M("goods")->alias('g')->
        join('type t ON g.tid = t.id')->
        join('goods_pic p ON g.id = p.gid')->
        join('business b ON g.bid = b.id')->
        field($define) ->group('g.id')->where($where) ->select();
        echo $this->e_json($list);
    }











}